Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(jest-transformer): add babel-preset-jest dependency #1112

Merged
merged 2 commits into from
Mar 18, 2019

Conversation

trevor-bliss
Copy link
Contributor

Details

The Jest transformer imports and uses babel-preset-jest directly but does not declare it as a dependency.

Although always not fully correct, this did not result in any errors before because the dependency would get hoisted to the project level node_modules via other Jest dependencies anyway. In newer versions of Jest, however, babel-preset-jest is nested in jest-config/node_modules and not accessible by the transformer.

Does this PR introduce a breaking change?

  • Yes
  • No

@salesforce-best-lwc-internal
Copy link

Benchmark results

Base commit: db59b74 | Target commit: 07abf05

lwc-engine-benchmark

table-append-1k metric base(db59b74) target(07abf05) trend
benchmark-table/append/1k duration 149.95 (±4.75 ms) 150.45 (±4.35 ms) +0.5ms (0.3%) 👌
table-clear-1k metric base(db59b74) target(07abf05) trend
benchmark-table/clear/1k duration 10.50 (±0.60 ms) 10.70 (±0.80 ms) +0.2ms (1.9%) 👌
table-create-10k metric base(db59b74) target(07abf05) trend
benchmark-table/create/10k duration 877.75 (±5.00 ms) 881.85 (±6.00 ms) +4.1ms (0.5%) 👎
table-create-1k metric base(db59b74) target(07abf05) trend
benchmark-table/create/1k duration 117.75 (±3.20 ms) 116.50 (±3.00 ms) -1.3ms (1.1%) 👌
table-update-10th-1k metric base(db59b74) target(07abf05) trend
benchmark-table/update-10th/1k duration 73.60 (±2.05 ms) 84.25 (±2.00 ms) +10.7ms (14.5%) 👎
tablecmp-append-1k metric base(db59b74) target(07abf05) trend
benchmark-table-component/append/1k duration 221.65 (±9.60 ms) 226.90 (±10.30 ms) +5.3ms (2.4%) 👌
tablecmp-clear-1k metric base(db59b74) target(07abf05) trend
benchmark-table-component/clear/1k duration 6.20 (±1.10 ms) 5.85 (±0.95 ms) -0.3ms (5.6%) 👌
tablecmp-create-10k metric base(db59b74) target(07abf05) trend
benchmark-table-component/create/10k duration 1749.50 (±11.70 ms) 1742.90 (±8.90 ms) -6.6ms (0.4%) 👍
tablecmp-create-1k metric base(db59b74) target(07abf05) trend
benchmark-table-component/create/1k duration 207.10 (±4.35 ms) 211.75 (±5.55 ms) +4.7ms (2.2%) 👎
tablecmp-update-10th-1k metric base(db59b74) target(07abf05) trend
benchmark-table-component/update-10th/1k duration 68.70 (±4.55 ms) 69.25 (±5.25 ms) +0.6ms (0.8%) 👌
wc-append-1k metric base(db59b74) target(07abf05) trend
benchmark-table-wc/append/1k duration 232.05 (±15.05 ms) 230.90 (±15.55 ms) -1.2ms (0.5%) 👌
wc-clear-1k metric base(db59b74) target(07abf05) trend
benchmark-table-wc/clear/1k duration 10.75 (±1.30 ms) 11.10 (±1.60 ms) +0.4ms (3.3%) 👌
wc-create-10k metric base(db59b74) target(07abf05) trend
benchmark-table-wc/create/10k duration 1838.70 (±12.45 ms) 1905.75 (±14.40 ms) +67.1ms (3.6%) 👎
wc-create-1k metric base(db59b74) target(07abf05) trend
benchmark-table-wc/create/1k duration 218.25 (±4.95 ms) 217.40 (±5.80 ms) -0.8ms (0.4%) 👌
wc-update-10th-1k metric base(db59b74) target(07abf05) trend
benchmark-table-wc/update-10th/1k duration 69.65 (±5.30 ms) 67.90 (±5.15 ms) -1.8ms (2.5%) 👌

@trevor-bliss trevor-bliss changed the title fix(jest-transformer):add babel-preset-jest dependency fix(jest-transformer): add babel-preset-jest dependency Mar 14, 2019
@@ -16,6 +16,7 @@
"@babel/plugin-transform-modules-commonjs": "7.1.0",
"@babel/template": "~7.1.2",
"@lwc/errors": "0.37.0",
"babel-preset-jest": "^24.0.0",
"deasync": "0.1.14"
},
"peerDependencies": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we add instead jest as a peer dependency?
How does other jest transformers deal with this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can add jest as a peer dependency, but we still need a dependency here on babel-preset-jest. This package works with the latest versions of Jest (and I encourage users to stay relatively current), but babel-preset-jest isn't accessible from this package even if the consuming project has a jest dependency.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I don't think we need jest as a peer dependency here. This package declares it's own dependencies for the what it uses and the input/output of the transformer hasn't changed in recent versions. It takes in the source code and file path and returns the compiled/transformed code. That should work for older and newer versions of Jest.

We can add a peer dependency for Jest 24 because that's what we want consumers to use but it won't break them to be on Jest 23 so I don't think we should burden them with the warning message if it's not a hard requirement.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are assuming here that jest has not introduced a breaking change in babel-preset-jest between 23 and 24.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only breaking change Jest listed between 23 and 24 for this package was for to a change that required Babel 7, but the transformer has been on 7 for a while.

I can add the peer dependency just to be safe. I feel like this is moving in a direction where we want the Jest related packages in here to match the Jest major versions though. Similar to how ts-jest does it.

@salesforce-best-lwc-internal
Copy link

Benchmark results

Base commit: 5eb8bcc | Target commit: 2ac552b

lwc-engine-benchmark

table-append-1k metric base(5eb8bcc) target(2ac552b) trend
benchmark-table/append/1k duration 151.15 (±4.60 ms) 148.80 (±4.20 ms) -2.3ms (1.6%) 👍
table-clear-1k metric base(5eb8bcc) target(2ac552b) trend
benchmark-table/clear/1k duration 10.30 (±0.40 ms) 10.45 (±0.65 ms) +0.1ms (1.5%) 👌
table-create-10k metric base(5eb8bcc) target(2ac552b) trend
benchmark-table/create/10k duration 887.70 (±6.15 ms) 880.70 (±4.90 ms) -7.0ms (0.8%) 👍
table-create-1k metric base(5eb8bcc) target(2ac552b) trend
benchmark-table/create/1k duration 117.20 (±2.70 ms) 117.10 (±3.60 ms) -0.1ms (0.1%) 👌
table-update-10th-1k metric base(5eb8bcc) target(2ac552b) trend
benchmark-table/update-10th/1k duration 73.65 (±1.55 ms) 73.70 (±1.95 ms) +0.0ms (0.1%) 👌
tablecmp-append-1k metric base(5eb8bcc) target(2ac552b) trend
benchmark-table-component/append/1k duration 223.20 (±8.30 ms) 225.00 (±9.60 ms) +1.8ms (0.8%) 👌
tablecmp-clear-1k metric base(5eb8bcc) target(2ac552b) trend
benchmark-table-component/clear/1k duration 5.45 (±0.65 ms) 5.80 (±0.90 ms) +0.4ms (6.4%) 👌
tablecmp-create-10k metric base(5eb8bcc) target(2ac552b) trend
benchmark-table-component/create/10k duration 1736.25 (±11.20 ms) 1737.05 (±11.30 ms) +0.8ms (0.0%) 👌
tablecmp-create-1k metric base(5eb8bcc) target(2ac552b) trend
benchmark-table-component/create/1k duration 210.20 (±5.10 ms) 205.70 (±5.20 ms) -4.5ms (2.1%) 👍
tablecmp-update-10th-1k metric base(5eb8bcc) target(2ac552b) trend
benchmark-table-component/update-10th/1k duration 65.80 (±3.55 ms) 68.20 (±4.65 ms) +2.4ms (3.6%) 👌
wc-append-1k metric base(5eb8bcc) target(2ac552b) trend
benchmark-table-wc/append/1k duration 230.85 (±17.55 ms) 226.00 (±17.95 ms) -4.9ms (2.1%) 👌
wc-clear-1k metric base(5eb8bcc) target(2ac552b) trend
benchmark-table-wc/clear/1k duration 10.35 (±1.40 ms) 11.00 (±1.15 ms) +0.6ms (6.3%) 👌
wc-create-10k metric base(5eb8bcc) target(2ac552b) trend
benchmark-table-wc/create/10k duration 1887.15 (±15.40 ms) 1870.05 (±15.15 ms) -17.1ms (0.9%) 👍
wc-create-1k metric base(5eb8bcc) target(2ac552b) trend
benchmark-table-wc/create/1k duration 219.05 (±5.95 ms) 213.65 (±3.90 ms) -5.4ms (2.5%) 👍
wc-update-10th-1k metric base(5eb8bcc) target(2ac552b) trend
benchmark-table-wc/update-10th/1k duration 67.60 (±3.95 ms) 69.25 (±5.00 ms) +1.7ms (2.4%) 👌

@salesforce-best-lwc-internal
Copy link

Benchmark results

Base commit: 5eb8bcc | Target commit: 2ac552b

lwc-engine-benchmark

table-append-1k metric base(5eb8bcc) target(2ac552b) trend
benchmark-table/append/1k duration 151.15 (±4.60 ms) 151.80 (±3.60 ms) +0.7ms (0.4%) 👌
table-clear-1k metric base(5eb8bcc) target(2ac552b) trend
benchmark-table/clear/1k duration 10.30 (±0.40 ms) 10.50 (±0.70 ms) +0.2ms (1.9%) 👌
table-create-10k metric base(5eb8bcc) target(2ac552b) trend
benchmark-table/create/10k duration 887.70 (±6.15 ms) 885.40 (±10.80 ms) -2.3ms (0.3%) 👌
table-create-1k metric base(5eb8bcc) target(2ac552b) trend
benchmark-table/create/1k duration 117.20 (±2.70 ms) 118.25 (±2.65 ms) +1.0ms (0.9%) 👌
table-update-10th-1k metric base(5eb8bcc) target(2ac552b) trend
benchmark-table/update-10th/1k duration 73.65 (±1.55 ms) 72.95 (±1.15 ms) -0.7ms (1.0%) 👌
tablecmp-append-1k metric base(5eb8bcc) target(2ac552b) trend
benchmark-table-component/append/1k duration 223.20 (±8.30 ms) 229.85 (±12.55 ms) +6.7ms (3.0%) 👎
tablecmp-clear-1k metric base(5eb8bcc) target(2ac552b) trend
benchmark-table-component/clear/1k duration 5.45 (±0.65 ms) 5.65 (±0.90 ms) +0.2ms (3.7%) 👌
tablecmp-create-10k metric base(5eb8bcc) target(2ac552b) trend
benchmark-table-component/create/10k duration 1736.25 (±11.20 ms) 1743.60 (±12.95 ms) +7.3ms (0.4%) 👎
tablecmp-create-1k metric base(5eb8bcc) target(2ac552b) trend
benchmark-table-component/create/1k duration 210.20 (±5.10 ms) 209.60 (±6.55 ms) -0.6ms (0.3%) 👌
tablecmp-update-10th-1k metric base(5eb8bcc) target(2ac552b) trend
benchmark-table-component/update-10th/1k duration 65.80 (±3.55 ms) 68.75 (±4.45 ms) +3.0ms (4.5%) 👌
wc-append-1k metric base(5eb8bcc) target(2ac552b) trend
benchmark-table-wc/append/1k duration 230.85 (±17.55 ms) 227.05 (±15.45 ms) -3.8ms (1.6%) 👌
wc-clear-1k metric base(5eb8bcc) target(2ac552b) trend
benchmark-table-wc/clear/1k duration 10.35 (±1.40 ms) 10.70 (±1.60 ms) +0.3ms (3.4%) 👌
wc-create-10k metric base(5eb8bcc) target(2ac552b) trend
benchmark-table-wc/create/10k duration 1887.15 (±15.40 ms) 1859.70 (±7.90 ms) -27.5ms (1.5%) 👍
wc-create-1k metric base(5eb8bcc) target(2ac552b) trend
benchmark-table-wc/create/1k duration 219.05 (±5.95 ms) 219.45 (±4.20 ms) +0.4ms (0.2%) 👌
wc-update-10th-1k metric base(5eb8bcc) target(2ac552b) trend
benchmark-table-wc/update-10th/1k duration 67.60 (±3.95 ms) 66.75 (±4.60 ms) -0.8ms (1.3%) 👌

@trevor-bliss trevor-bliss merged commit 1f12803 into master Mar 18, 2019
@trevor-bliss trevor-bliss deleted the tbliss/transformer-babel-jest-dep branch March 18, 2019 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants